package com.shanshi.activity;

import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;

import com.google.gson.Gson;
import com.shanshi.activity.response.BillDetail;
import com.shanshi.activity.tool.OkHttpTool;


public class BillDetailed extends MainActivity implements OnClickListener{

	private TextView tv;
	private TextView Iv;
	private int billId;
	private TextView bill_money;
	private TextView bill_time;
	private TextView bill_tradetype;
	private TextView bill_store;
	private TextView bill_ordernum;
	private TextView bill_type;
	private BillDetail bill;
	private ImageView billdetail_close;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.billdetailed);

		billId = getIntent().getIntExtra("billId",5);
		tv = (TextView) findViewById(R.id.titls2);
		tv.setText("交易明细");
		Iv = (TextView) findViewById(R.id.cancel);
		Iv.setText("");
		bill_money = (TextView) findViewById(R.id.bill_money);
		bill_time = (TextView) findViewById(R.id.bill_time);
		bill_tradetype = (TextView) findViewById(R.id.bill_tradetype);
		bill_store = (TextView) findViewById(R.id.bill_store);
		bill_ordernum = (TextView) findViewById(R.id.bill_ordernum);
		bill_type = (TextView) findViewById(R.id.bill_type);
		billdetail_close = (ImageView) findViewById(R.id.billdetail_close);
		billdetail_close.setOnClickListener(this);

		OkHttpTool.doGet(OkHttpTool.BASE_URL + "bills/" + billId + "/detailInfo", new OkHttpTool.setOkhttpListener() {
			@Override
			public void onSuccess(String s) {
				bill = new Gson().fromJson(s,BillDetail.class);
				handler.sendEmptyMessage(1);
				Log.e("==bill.toString()===",bill.toString());
			}

			@Override
			public void onFail() {

			}
		});

	}
	
	@Override
	public void onClick(View v) {
		
		finish();
	}

	Handler handler=new Handler() {
		public void handleMessage(android.os.Message msg) {
			switch (msg.what) {
				case 1:
					bill_money.setText("￥"+bill.getData().getMoney());
					bill_time.setText(bill.getData().getTime());
					switch (bill.getData().getTradeType()){
						case 1:
							bill_tradetype.setText("支付宝");
							break;
						case 2:
							bill_tradetype.setText("微信");
							break;
						case 3:
							bill_tradetype.setText("现金");
							break;
						case 4:
							bill_tradetype.setText("会员卡");
							break;
						case 5:
							bill_tradetype.setText("账户余额");
							break;
					}
					bill_store.setText(bill.getData().getShopName());
					bill_ordernum.setText(bill.getData().getOrderNum());
					switch (bill.getData().getType()){
						case 0:
							bill_type.setText("购物");
							break;
						case 1:
							bill_type.setText("充值");
							break;
						case 2:
							bill_type.setText("退款");
							break;
						case 3:
							bill_type.setText("提现");
							break;
					}
					break;
			}
		}
	};
}
